window._IOF = {


    //构造道具对象
    createObjByName:function(name,param){

        if(_EQUIP[name]){

            return _IOF.createEquip(name,param);

        }else if(_SKILL[name]){

            return _IOF.createSkill(name,param);

        }else if(_SKILLBD[name]){

            return _IOF.createSkillbd(name,param);

        }else if(_FIGHTITEM[name]){

            return _IOF.createFightItem(name,param);
        }else if(_M[name]){
            return _IOF.createMaterial(name,param);
        }else if(_MAKE[name]){
            return _IOF.createMakeBook(name,param);
        }else if(_SKILLTEAM[name]){
            return _IOF.createSkillteam(name,param);
        }

        return null;
    },

    //{attr:{attack:20,speed:10,lianji:1},type:'测试刀',qua:'SS',stone:[1,2,3,4]}
    createEquip:function(type,param){
        
        var tempattr = _CU.cloneObj(_EQUIP[type].attr);
        var tempqua = _EQUIP[type].qua?_EQUIP[type].qua:'D';

        if(param&&param.qua){
            tempqua = param.qua;
        }

        return {
            objtype:'equip',
            attr:tempattr,
            type:type,
            qua:tempqua
        };
    },

    createSkill:function(type,param){
        return {objtype:'skill',type:type};
    },

    createSkillbd:function(type,param){
        return {objtype:'skillbd',type:type};
    },

    createFightItem:function(type,param){
        return {objtype:'fightitem',type:type};
    },

    createMaterial:function(type,param){
        return {objtype:'material',type:type};
    },

    createMakeBook:function(type,param){
        return {objtype:'makebook',type:type};
    },

    createSkillteam:function(type,param){
        return {objtype:'teamskill',type:type};
    },

    /*
    物品价格P物品等级I品质基数
    R:(C:100,B:200,A:400,s:700,SS:1400)
    品质系数Q:(C:1,B:1.5,A:2,S:3,SS:5)
    有物品等级(装备) :P=(L+100)^2*Q
    无物品等级:P=(R+100)~2
    */
    getGoodsPrice:function(goodsInfo){

        var name = goodsInfo.type;
        var goodslv = null;
        var goodsqua = null;

        if(_EQUIP[name]){
            goodslv = _EQUIP[name].lv;
            goodsqua = goodsInfo.qua;
        }else if(_SKILL[name]){
            var price = 0;
            if(_SKILL[name].xw){
                for(var key in _SKILL[name].xw){
                    price +=  _SKILL[name].xw[key]*1000;
                }
            }
            return price<=0?1:price;
        }else if(_SKILLBD[name]){
            var price = 0;
            if(_SKILLBD[name].xw){
                for(var key in _SKILLBD[name].xw){
                    price +=  _SKILLBD[name].xw[key]*1000;
                }
            }
            return price<=0?1:price;
        }else if(_FIGHTITEM[name]){
            goodslv = _FIGHTITEM[name].lv;
            goodsqua = _FIGHTITEM[name].qua;
        }else if(_M[name]){
            goodslv = _M[name].lv;
            goodsqua = _M[name].qua;
        }else if(_MAKE[name]){
            goodslv = _MAKE[name].lv;
            goodsqua = _MAKE[name].qua;
        }else if(_SKILLTEAM[name]){
            goodslv = _SKILLTEAM[name].lv;
            goodsqua = _SKILLTEAM[name].qua;
        }
        if(!goodsqua||!_CS.qua[goodsqua]){
            return 1;
        }else if(!goodslv){
            var r = _CS.qua[goodsqua].r;
            return Math.floor((r+100)*(r+100));
        }else{
            var q = _CS.qua[goodsqua].q;
            return Math.floor((goodslv+100)*(goodslv+100)*q);
        }
    },

    getGoodsImg:function(goodsInfo){

        var name = goodsInfo.type;
        var goodsImg = null;

        if(_EQUIP[name]){

            goodsImg = _EQUIP[name].img;

        }else if(_SKILL[name]){
            
            goodsImg = _SKILL[name].img;

        }else if(_SKILLBD[name]){

            goodsImg = _SKILLBD[name].img;

        }else if(_FIGHTITEM[name]){

            goodsImg = _FIGHTITEM[name].img;

        }else if(_M[name]){

            goodsImg = _M[name].img;

        }else if(_MAKE[name]){
            
            goodsImg = _MAKE[name].img;

        }else if(_SKILLTEAM[name]){
            goodsImg = _SKILLTEAM[name].img;
        }

        if(!goodsImg){
            return _CS.defaultItemImg;
        }

        return goodsImg;
    },

    //道具属性详情
    getGoodsAttrStr:function(goodsInfo){

        var name = goodsInfo.type;

        if(_EQUIP[name]){

            var equipAttr = _ROLEDATA.getAttrOfEquip(goodsInfo);

            return _IOF.getAttrString(equipAttr);

        }else if(_SKILLBD[name]){


            var result = _IOF.getAttrString(_SKILLBD[name].attr);

            return result;

        }else if(_M[name]){

            var attrStr = _IOF.getAttrString(_M[name].attr);
            
            return attrStr;
        }

        return '未知';

    },

    getSkillDrop:function(key){

        var baseInfo = "";
        if(_SKILLBD[key]&&_SKILLBD[key].bossflag){
            var npcname = _SKILLBD[key].bossflag.replace("专属","");
            var npcplace = _ME.getNpcPlace(npcname);
            if(_SKILLBD[key].bossflag.indexOf("专属")==-1){
                baseInfo+="掉落:"+_SKILLBD[key].bossflag;
            }else{
                baseInfo+=_SKILLBD[key].bossflag+"[三周目掉落]";
            }
            if(npcplace){
                baseInfo+="\n地点:"+npcplace;
            }
        }else if(_SKILL[key]&&_SKILL[key].bossflag){
            var npcname = _SKILL[key].bossflag.replace("专属","");
            var npcplace = _ME.getNpcPlace(npcname);
            if(_SKILL[key].bossflag.indexOf("专属")==-1){
                baseInfo+="\n掉落:"+_SKILL[key].bossflag;
            }else{
                baseInfo+="\n"+_SKILL[key].bossflag+"[三周目掉落]";
            }
            if(npcplace){
                baseInfo+="\n地点:"+npcplace;
            }
        }

        return baseInfo;
    },

    //道具详情
    getGoodsDetailStr:function(goodsInfo){

        var name = goodsInfo.type;

        if(_MAKE[name]){

            var makebookstr = "制作目标:"+_MAKE[name].item+"\n";

            for(var i=0;i<_MAKE[name].arr.length;i++){

                var tempM = _MAKE[name].arr[i];

                makebookstr+=tempM.type+"*"+tempM.nmb+"\n";

            }

            return makebookstr;
        }else if(_EQUIP[name]){

            var equipAttr = _ROLEDATA.getAttrOfEquip(goodsInfo);
            var equipStr = _IOF.getAttrString(equipAttr);
            equipStr+="\n类型:"+(_EQUIP[name].type?_EQUIP[name].type:'无');
            equipStr+="\n等级:"+_EQUIP[name].lv;
            equipStr+="\n"+XWH.getStrOfXwObj(goodsInfo.xw);
            return equipStr;

        }else if(_SKILL[name]){
            var skillpre = "[主动]"

            if(_SKILL[name].ejob){
                skillpre+="\n职业限定:"+_SKILL[name].ejob.join(",");
            }

            if(_SKILL[name].animals){
                if(_ANIMALS[_SKILL[name].animals]){
                    var aniconf = _ANIMALS[_SKILL[name].animals];
                    skillpre+=(_SKILL[name].type?("["+_SKILL[name].type+"]"):"")+"\n"+_SKILL[name].des;
                    if(aniconf.attr){
                        skillpre+="\n获得属性:\n"+_IOF.getAttrString(aniconf.attr);
                    }
                    if(aniconf.skill&&aniconf.skill.length>0){
                        skillpre+="获得技能:"+aniconf.skill.join(',');
                    }
                }else{
                    skillpre+=(_SKILL[name].type?("["+_SKILL[name].type+"]"):"")+"\n"+_SKILL[name].des;
                }
            }else{
                skillpre+=(_SKILL[name].type?("["+_SKILL[name].type+"]"):"")+"\n"+_SKILL[name].des;
            }
            skillpre+="\n"+_SKILLHEPLER.getXWofSkillDes(name);
            skillpre+=_IOF.getSkillDrop(name);
            return skillpre;
        }else if(_SKILLBD[name]){
            var skillpre = "[被动]\n";
            if(_SKILLBD[name].animals){
                if(_ANIMALS[_SKILLBD[name].animals]){
                    var skilldes = _IOF.getAttrString(_SKILLBD[name].attr);
                    var aniconf = _ANIMALS[_SKILLBD[name].animals];
                    skilldes+="濒死变身:"+_SKILLBD[name].animals;
                    if(aniconf.attr){
                        skilldes+="\n获得属性:\n"+_IOF.getAttrString(aniconf.attr);
                    }
                    if(aniconf.skill&&aniconf.skill.length>0){
                        skilldes+="获得技能:"+aniconf.skill.join(',');
                    }
                    skillpre+=skilldes;
                }else{
                    skillpre+=_IOF.getAttrString(_SKILLBD[name].attr)+"\n濒死变身:"+_SKILLBD[name].animals+"(暂未实装)";
                }
            }else{
                skillpre+=_IOF.getAttrString(_SKILLBD[name].attr);
            }

            if(_SKILLBD[name].xw){
                skillpre+=XWH.getStrOfXwObj(_SKILLBD[name].xw)+"\n";
            }

            if(_SKILLBD[name].exc&&_SKILLBD[name].exc.length>0){
                skillpre+="限定职业:"+_SKILLBD[name].exc.join(',');
            }
            skillpre+=_IOF.getSkillDrop(name);
            return skillpre;

        }else if(_FIGHTITEM[name]){
            if(!_FIGHTITEM[name].isZhaohuan){
                return _FIGHTITEM[name].des;
            }else{
                return _FIGHTITEM[name].des+"\n当前:"+(window.gameData.catchMonster?window.gameData.catchMonster:'无');
            }

        }else if(_M[name]){
            if(!_M[name].des){
                var attrStr = _IOF.getAttrString(_M[name].attr);
                if(_M[name].isStone){
                    attrStr+="\n可镶嵌";
                }
                if(_M[name].ftype){
                    attrStr+="\n五行:"+_M[name].ftype;
                }
                if(_M[name].qua){
                    attrStr+="\n品质:"+_M[name].qua;
                }
                return attrStr;
            }   
            return _M[name].des;
        }else if(_SKILLTEAM[name]){
            return  _SKILLTEAM[name].des;
        }

        return '未知';
    },

    getGoodsFtype:function(goodsInfo){

        var name = goodsInfo.type;
        var ftype = null;

        if(_SKILL[name]){
            
            ftype = _SKILL[name].ftype;

        }else if(_SKILLBD[name]){

            ftype = _SKILLBD[name].ftype;

        }else if(_M[name]){

            ftype = _M[name].ftype;

        }
        
        if(ftype!=null&&_CS.ftype[ftype]){

            return {color:_CS.ftype[ftype].color,ftype:ftype};

        }

        return null;

    },

    getGoodsColor:function(goodsInfo){

        var name = goodsInfo.type;
        var ftype = null;
        var qua = null;

        if(_EQUIP[name]){

            qua = goodsInfo.qua;

        }else if(_SKILL[name]){
            
            //ftype = _SKILL[name].ftype;

        }else if(_SKILLBD[name]){

            //ftype = _SKILLBD[name].ftype;

        }else if(_FIGHTITEM[name]){

            qua = _FIGHTITEM[name].qua;

        }else if(_M[name]){

            //qua = _M[name].qua;
            ftype = _M[name].ftype;
        }else if(_SKILLTEAM[name]){
            qua = _SKILLTEAM[name].qua;
        }
        
        if(qua!=null){

            return _CS.qua[qua].color;

        }else if(ftype!=null){

            return _CS.ftype[ftype].color;
        }

        return "#000000";
    },

    getGoodsNmb:function(goodsInfo){
        return goodsInfo.nmb?goodsInfo.nmb:1;
    },


    getAttrString:function(data){

        var result = "";

       
        for(var key in data){

            if(
                data[key]!=0
                &&_DICT[key]
            ){

                var name = _DICT[key];

                result+=name+":"+data[key]+"\n";

            }

        }

        return result;
    },


}